/**   
 * @Title: UserDaoImpl.java 
 * @Package com.foreveross.smsh.models.user.dao.impl 
 * @Description: TODO 
 * @author lixiaodong lixiaodong@foreveross.com  
 * @date 2016年3月4日 下午4:00:47 
 * @version V1.0   
 */
package com.foreveross.smsh.models.user.dao.impl;

import java.math.BigInteger;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.transform.Transformers;
import org.springframework.stereotype.Repository;

import com.foreveross.smsh.common.Paginator;
import com.foreveross.smsh.core.dao.impl.BaseDaoImpl;
import com.foreveross.smsh.models.user.dao.UserDao;
import com.foreveross.smsh.models.user.pojo.User;

/** 
 * @ClassName: UserDaoImpl 
 * @Description: TODO
 * @author A18ccms a18ccms_gmail_com 
 * @date 2016年3月4日 下午4:00:47 
 *  
 */
@Repository
public class UserDaoImpl extends BaseDaoImpl<User> implements UserDao{

	@Override
	public void queryUser(Paginator<User> user) {
		//sql
		String countsql ="select count(id) from tbl_user";
		BigInteger count = (BigInteger) this.getSession().createSQLQuery(countsql).uniqueResult();
		user.setTotalCount(count.longValue());
		String sql ="select u.id id,u.nicename nicename,u.username from tbl_user u ";
		SQLQuery  query =this.getSession().createSQLQuery(sql);
		query.addScalar("id");
		query.addScalar("nicename");   
		query.addScalar("username");  
		query.setResultTransformer(Transformers.aliasToBean(User.class));  
		query.setFirstResult(user.getStartResult());
		query.setMaxResults(user.getPageSize());
		@SuppressWarnings("unchecked")
		List<User> users = query.list();
		user.setDataList(users);
	
		
		//hql
	/*	String hql = "select * from User ";
		Query q = getSession().createQuery(hql);
		q.setFirstResult(user.getStartResult());
		q.setMaxResults(user.getPageSize());
		List<User> u =q.list();*/
		
		
	}

}
